﻿using System;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Design;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Design;

namespace SSIS.MS.xRM.ConnectionManager
{
    class XRMConnectionManagerUI : IDtsConnectionManagerUI
    {
        private Microsoft.SqlServer.Dts.Runtime.ConnectionManager _connectionManager;
        private IServiceProvider _serviceProvider;

        public void Initialize(Microsoft.SqlServer.Dts.Runtime.ConnectionManager connectionManager, IServiceProvider serviceProvider)
        {
            _connectionManager = connectionManager;
            _serviceProvider = serviceProvider;
        }

        public bool Edit(IWin32Window parentWindow, Connections connections, ConnectionManagerUIArgs connectionUIArg)
        {
            return EditSqlConnection(parentWindow);
        }

        public void Delete(IWin32Window parentWindow)
        {
            throw new NotImplementedException();
        }

        public bool New(IWin32Window parentWindow, Connections connections, ConnectionManagerUIArgs connectionUIArg)
        {
            var clipboardService = (IDtsClipboardService)_serviceProvider.GetService(typeof(IDtsClipboardService));
            if (clipboardService != null)
            {
                if (clipboardService.IsPasteActive)
                {
                    return true;
                }
            }

            return EditSqlConnection(parentWindow);
        }

        private bool EditSqlConnection(IWin32Window parentWindow)
        {
            return false;
        }
    }
}
